package com.tunnel.common.util;

/**
 * 用户提取http请求的请求头
 */
public class HttpUtil {
   static   String httpRequest = "GET /controller/test HTTP/1.1\r\n" +
            "User-Agent: Apifox/1.0.0 (https://apifox.com)\r\n" +
            "Accept: */*\r\n" +
            "Host: 127.0.0.1:8888\r\n" +
            "Accept-Encoding: gzip, deflate, br\r\n" +
            "Connection: keep-alive\r\n" +
            "content-length: 0";
    public static String getUri(String request){
        String line = "";
        if (request == null || request.isEmpty()) {
            return "";
        }

        // 使用 \r\n 分割请求字符串
        String[] lines = request.split("\\r?\\n");
        if (lines.length > 0) {
            line= lines[0];
        }
        // 使用空格分割第一行
        String[] parts = line.split(" ");
        if (parts.length > 1) {
            return parts[1];
        }

        return "";
    }
    public static String getRealUri(String request){
        String line = "";
        if (request == null || request.isEmpty()) {
            return "";
        }

        // 使用 \r\n 分割请求字符串
        String[] lines = request.split("\\r?\\n");
        if (lines.length > 0) {
            line= lines[0];
        }
        // 使用空格分割第一行
        String[] parts = line.split(" ");
        if (parts.length > 1) {
            return parts[1];
        }

        return "";
    }


    public static void main(String[] args) {
        String uri = getUri(httpRequest);
        uri= httpRequest.replace(uri,"/a/b");
        System.out.println(uri);
    }
}
